package com.lagou.controller;

import com.lagou.pojo.Token;
import com.lagou.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UserController
 * @Description
 * @Author playboy
 * @Date 2021/6/25 9:01 下午
 * @Version 1.0
 **/
@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {
	private static Logger log = LoggerFactory.getLogger(UserController.class);

	@Autowired
	private UserService userService;

	@RequestMapping("/register/{email}/{password}/{code}")
	public boolean register(@PathVariable("email") String email,
							@PathVariable("password") String password,
							@PathVariable("code") String code) {
		return userService.register(email, password, code);
	}

	@RequestMapping("/isRegistered/{email}")
	public boolean isRegistered(@PathVariable("email") String email) {
		return userService.isRegistered(email);
	}

	@RequestMapping("/login/{email}/{password}")
	public String login(@PathVariable("email") String email,
						@PathVariable("password") String password) {
		Token token = userService.login(email, password);
		return token.getToken();
	}

	@RequestMapping("/info/{token}")
	public String info(@PathVariable("token") String token) {
		return userService.info(token);
	}
}
